<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">

    <link type="text/css" rel="stylesheet" href="__STATIC__/uploads/css/fileinput.css"/>
    <script type="text/javascript" src="__STATIC__/uploads/js/fileinput.js"></script>
    <script type="text/javascript" src="__STATIC__/uploads/js/fileinput_locale_zh.js"></script>
    <link type="text/css" rel="stylesheet" href="__STATIC__/uploads/css/bootstrap.min.css"/>

</head>
<body>
<br>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<form class="layui-form" action="" method="post" enctype="multipart/form-data"  onsubmit="return false" id="comment" style="width: 50%">
    <br>
    <div class="layui-form-item">
        <label class="layui-form-label">集合名</label>
        <div class="layui-input-block">
            <input type="text" id="title" placeholder="请输入集合名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea lay-verify="article_desc" id="introduce"  name="text" style="width: 100%;height: 100px"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block" >
            <input type="file" name="file" id="uploads" multiple class="file-loading" />
            <input type="text"  id="icon_path" value="" hidden>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">视频</label>
        <div class="layui-input-block" >
            <input type="file" name="file" id="video" multiple class="file-loading" />
            <input type="text" id="video_path" value="" hidden>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">教师</label>
        <div class="layui-input-block">
            <select id="jsname" lay-verify="required">
                <option value="">请选择</option>
               {foreach $teacher as $val}
                    <option value="{$val.id}">{$val.title}</option>
               {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地区</label>
        <div class="layui-input-block">
            <select id="city" lay-verify="required">
                {foreach $city as $val}
                 <option value="{$val.id}">{$val.region_name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-block">
            <select id="cat_id" lay-verify="required">
                {foreach $cat as $val}
                <option value="{$val.cat_id}">{$val.cat_name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="add">立即添加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use('layedit', function(){
        layedit = layui.layedit;
        index = layedit.build('introduce', {tool: [
            'strong' //加粗
            ,'italic' //斜体
            ,'underline' //下划线
            ,'del' //删除线
        ]}); //建立编辑器
        //layedit.sync(index);
        edit = layedit.getContent(index);
    });
</script>
<script>
    $("#uploads").fileinput({
        language: 'zh', //设置语言
        uploadUrl: "{:url('/common/img')}", //上传的地址
        uploadExtraData: {path:'/public/uploads/gather/img'},
        allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        //dropZoneEnabled: false,//是否显示拖拽区域
        minImageWidth: 200, //图片的最小宽度
        minImageHeight: 200,//图片的最小高度
        maxImageWidth: 200,//图片的最大宽度
        maxImageHeight: 200,//图片的最大高度
//        maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
    }).on("fileuploaded", function (event, data, previewId, index) {
        $("#icon_path").val(data.response.img)
    });
</script>
<script>
    $("#video").fileinput({
        language: 'zh', //设置语言
        uploadUrl: "{:url('/common/video')}", //上传的地址
        uploadExtraData: {path:'/public/uploads/gather/video'},
        previewFileType:"video",
        allowedFileExtensions: ['mp4'],//接收的文件后缀
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        //dropZoneEnabled: false,//是否显示拖拽区域
        minImageWidth: 200, //图片的最小宽度
        minImageHeight: 200,//图片的最小高度
        maxImageWidth: 200,//图片的最大宽度
        maxImageHeight: 200,//图片的最大高度
        maxFileSize: 1000000,//单位为kb，如果为0表示不限制文件大小
        //minFileCount: 0,
        maxFileCount: 1, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
    }).on("fileuploaded", function (event, data, previewId, index) {
        loading = layer.load(2, {time: 100*1000});
        if(event.date){
            layer.close(loading);
            $("#video_path").val(data.response.video)
        }

    });
</script>
<script>
    $("#add").click(function () {
        var introduce = layedit.getContent(index);
        var title     = $("#title").val();
        var video_path= $("#video_path").val();
        var icon_path = $("#icon_path").val();
        var cat_id    = $("#cat_id").val();
        var city      = $("#city").val();
        var jsname    = $("#jsname").val();

        if(!introduce || !title || !icon_path)
        {
            layer.alert("请完善介绍，名称，以及封面图片")
            return;
        }

        $.ajax({
            url:"{:url('/video/addGather')}",
            data:{title:title,introduce:introduce,video_path:video_path,icon_path:icon_path,cat_id:cat_id,city:city,jsname:jsname},
            type:"post",
            dataType:"json",
            beforeSend:function () {
                index = layer.load(2, {time: 100*1000});
            },
            success:function(res){
                if(res.code){
                    layer.close(index);
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        })
    })
</script>